package com.cskaoyan.builder;

import com.cskaoyan.bean.Car;

/**
 * @author stone
 * @date 2021/11/17 10:56
 */
public class CarBuilder {

    //每一次获得一个新的builder的时候获得一个新的car
    Car car = new Car();
    //设置属性值的方法要针对于同一个实例来设置属性值
    //实例化过程就不能放在set方法里
    /*static {
        car = new Car();
    }*/

    //设置属性值方法
    public void setCarName(String name) {
        //如果car作为局部变量，build方法也没法返回该实例
        //car要作为全局变量
        //Car car = new Car();
        //car = new Car();
        car.setName(name);
    }

    public void setCarPrice(double price) {
        //Car car = new Car();
        car.setPrice(price);
    }

    public void setCarBrand(String brand) {
        //Car car = new Car();
        car.setBrand(brand);
    }

    //获得结果方法
    public Car build() {
        return car;
    }
}
